home *** CD-ROM | disk | FTP | other *** search
/ Assassins - Ultimate CD Games Collection 4 / Assassins 4 (1999)(Weird Science).iso / mui / mui_developer / c / examples / appwindow.c next >
C/C++ Source or Header  |  1997-03-10  |  3KB  |  142 lines

  1. #include "demo.h"
  2.  
  3.  
  4. /*
  5. ** App message callback hook. Note that the object given here
  6. ** is the object that called the hook, i.e. the one that got
  7. ** the icon(s) dropped on it.
  8. */
  9.  
  10. SAVEDS ASM LONG AppMsgFunc(REG(a2) APTR obj, REG(a1) struct AppMessage **x)
  11. {
  12.     struct WBArg *ap;
  13.     struct AppMessage *amsg = *x;
  14.     int i;
  15.     static char buf[256];
  16.     char *b=buf;
  17.  
  18.     for (ap=amsg->am_ArgList,i=0;i<amsg->am_NumArgs;i++,ap++)
  19.     {
  20.         NameFromLock(ap->wa_Lock,buf,sizeof(buf));
  21.         AddPart(buf,ap->wa_Name,sizeof(buf));
  22.         DoMethod(obj,MUIM_List_Insert,&b,1,MUIV_List_Insert_Bottom);
  23.     }
  24.  
  25.     return(0);
  26. }
  27.  
  28.  
  29. /*
  30. ** Having a function instead of a macro saves some code.
  31. */
  32.  
  33. APTR MakeLV(VOID)
  34. {
  35.     return(
  36.         ListviewObject,
  37.             MUIA_Listview_Input, FALSE,
  38.             MUIA_Listview_List , ListObject,
  39.                 ReadListFrame,
  40.                 MUIA_List_ConstructHook, MUIV_List_ConstructHook_String,
  41.                 MUIA_List_DestructHook , MUIV_List_DestructHook_String ,
  42.                 End,
  43.             End
  44.     );
  45. }
  46.  
  47.  
  48. int main(int argc,char *argv[])
  49. {
  50.     APTR app,window;
  51.     APTR lv1,lv2,lv3;
  52.     static const struct Hook AppMsgHook = { { NULL,NULL },(VOID *)AppMsgFunc,NULL,NULL };
  53.  
  54.     init();
  55.  
  56.     app = ApplicationObject,
  57.         MUIA_Application_Title      , "AppWindowDemo",
  58.         MUIA_Application_Version    , "$VER: AppWindowDemo 19.5 (12.02.97)",
  59.         MUIA_Application_Copyright  , "©1992/93, Stefan Stuntz",
  60.         MUIA_Application_Author     , "Stefan Stuntz",
  61.         MUIA_Application_Description, "Show AppWindow Handling",
  62.         MUIA_Application_Base       , "APPWINDOWDEMO",
  63.  
  64.         SubWindow, window = WindowObject,
  65.             MUIA_Window_Title    , "Drop icons on me!",
  66.             MUIA_Window_ID       , MAKE_ID('A','P','P','W'),
  67.             MUIA_Window_AppWindow, TRUE,
  68.  
  69.             WindowContents, VGroup,
  70.                 Child, HGroup,
  71.                     Child, lv1 = MakeLV(),
  72.                     Child, lv2 = MakeLV(),
  73.                     End,
  74.                 Child, lv3 = MakeLV(),
  75.                 End,
  76.  
  77.             End,
  78.  
  79.         End;
  80.  
  81.     if (!app)
  82.         fail(app,"Failed to create Application.");
  83.  
  84.     DoMethod(window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  85.         app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  86.  
  87.  
  88. /*
  89. ** Call the AppMsgHook when an icon is dropped on a listview.
  90. */
  91.  
  92.     DoMethod(lv1,MUIM_Notify,MUIA_AppMessage,MUIV_EveryTime,
  93.         lv1,3,MUIM_CallHook,&AppMsgHook,MUIV_TriggerValue);
  94.  
  95.     DoMethod(lv2,MUIM_Notify,MUIA_AppMessage,MUIV_EveryTime,
  96.         lv2,3,MUIM_CallHook,&AppMsgHook,MUIV_TriggerValue);
  97.  
  98.     DoMethod(lv3,MUIM_Notify,MUIA_AppMessage,MUIV_EveryTime,
  99.         lv3,3,MUIM_CallHook,&AppMsgHook,MUIV_TriggerValue);
  100.  
  101.  
  102. /*
  103. ** When we're iconified, the object lv3 shall receive the
  104. ** messages from icons dropped on our app icon.
  105. */
  106.  
  107.     set(app,MUIA_Application_DropObject,lv3);
  108.  
  109.  
  110. /*
  111. ** This is the ideal input loop for an object oriented MUI application.
  112. ** Everything is encapsulated in classes, no return ids need to be used,
  113. ** we just check if the program shall terminate.
  114. ** Note that MUIM_Application_NewInput expects sigs to contain the result
  115. ** from Wait() (or 0). This makes the input loop significantly faster.
  116. */
  117.  
  118.     set(window,MUIA_Window_Open,TRUE);
  119.  
  120.     {
  121.         ULONG sigs = 0;
  122.  
  123.         while (DoMethod(app,MUIM_Application_NewInput,&sigs) != MUIV_Application_ReturnID_Quit)
  124.         {
  125.             if (sigs)
  126.             {
  127.                 sigs = Wait(sigs | SIGBREAKF_CTRL_C);
  128.                 if (sigs & SIGBREAKF_CTRL_C) break;
  129.             }
  130.         }
  131.     }
  132.  
  133.     set(window,MUIA_Window_Open,FALSE);
  134.  
  135.  
  136. /*
  137. ** Shut down...
  138. */
  139.  
  140.     fail(app,NULL);
  141. }
  142.